package leetcode.D200.T155;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @File Info: leetcode -- <MinStack>
 * @Author: 18362
 * @Create: 2022-02-23 20:00:18 星期三
 */

class MinStack {

    private Deque<Integer> stack = new LinkedList<>();

    private Deque<Integer> value = new LinkedList<>();

    public MinStack() {
    }

    public void push(int val) {
        stack.addFirst(val);
        value.addFirst(stack.size() > 1 ? Math.min(value.getFirst(), val) : val);
    }

    public void pop() {
        stack.removeFirst();
        value.removeFirst();
    }

    public int top() {
        return stack.getFirst();
    }

    public int getMin() {
        return value.getFirst();
    }
}